#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include "../include/linked.h" 

  
struct node* add(struct node *head, char *string,int fdnum ) /*insert at beginning */
{
    struct node *temp;
    temp=(struct node *)malloc(sizeof(struct node));
    strcpy(temp->data,string);
    temp->fd_num = fdnum;
    if (head== NULL)
    {
    head=temp;
    head->next=NULL;
    }
    else
    {
    temp->next=head;
    head=temp;
    }
    return head;
}

/*delete a string from hash table*/
struct node* delete(struct node *head,int fdno)
{
    struct node *temp, *prev;
    temp=head;
    prev = temp;
    while(temp!=NULL)
    {
    if(temp->fd_num==fdno)
    {
       
        
         if(temp==head)
        {
        head=temp->next;
        free(temp);
        
        }
        else
        {

        prev->next=temp->next;
        free(temp);
        
        }
      return head;
    }
    else
    {
        prev=temp;
        temp= temp->next;
    }
    }
    return head;
}
/*search a string from hash table*/
int search(struct node *head,char *string)
{
    struct node *temp;
    temp=head;
    while(temp!=NULL)
    {
    if(strcmp(temp->data,string)==0)
    {
       
        return temp->fd_num;
        
    }
    else
    {
       
        temp= temp->next;
    }
    }
    return -1;
}

/*display the list*/

void display(struct node *head)
{
  struct node*temp;
  temp=head;
  while(temp!=NULL)
  {
   // printf(" %s ",temp->data);
   
   temp=temp->next;
  }
}
 
 

 
 

